//**************************************************************** 
// General purpose functions
//**************************************************************** 
// Log of changes: 
//   2006/02/08 - First release
//**************************************************************** 
// Check is empty or null
function isEmpty(str) {
  if(str == null || Trim(str) == "") return true;
  return false;
}
  
function LTrim(str) {
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
      j++;
    }
    s = s.substring(j, i);
  }
  return s;
}

function RTrim(str) {
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    var i = s.length - 1;
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
      i--;
    }
    s = s.substring(0, i+1);
  }
  return s;
}

function Trim(str) {
  return RTrim(LTrim(str));
}


	function valid(val) {
		if(val == null) return false;
		var str = val.toString();
		var enCount = 0;
		var chCount = 0;
		for(var i=0; i < str.length;i++) {
			var ch = str.charAt(i);
			if(i == 0 && ch == '-') continue;
			if(ch < '0' || ch > 'z') return false;
			if('a'<= ch  && ch <='z'){
				enCount++;
			}			
			if('0' <= ch  && ch <= '9'){
				chCount++;
			}							
		}
		if(chCount == str.length){
			return false;
		}
		if(enCount == str.length){
			return false;
		}			
		return true;
	}	
	function isNumAndChar(val) {
		if(val == null) return false;
		var str = val.toString();
		var enCount = 0;
		var chCount = 0;
		for(var i=0; i < str.length;i++) {
			var ch = str.charAt(i);
			if(ch < '0' || ch > 'z') return false;
						
		}		
		return true;
	}		
	function setFont(cout,value){
    	var temp ;
    	for(i=0; i<cout;i++){
   			temp = value[i];
    		eval("document.all." + temp + ".color='#ff0000'");
    	}
    }    
    function isCheckBoxselected(form1,fname){
		if (fname.length > 1){
			for (i=0;i< fname.length;i++){
				if (fname[i].checked == true){
					return true;
				}
			}
		}
		else if (fname.checked == true){
			return true;
		}
		return false;
	}
	function SelectAllCheckBox(form,fvalue){ 
	  if (form.indexs!=null){ 
	    var OnOff = form.indexs.checked; 
	    var tag =  fvalue ;
	    var theItem = form.elements[tag]; 
	    if (theItem!=null){ 
	      if (typeof(theItem.value)=='undefined'){ 
	        var i; 
	        for (i=0;i < theItem.length; i++){ 
	          var SubItem = theItem[i]; 
	          SubItem.checked = OnOff; 
	        } 
	      }else{ 
	        theItem.checked = OnOff; 
	      } 
	    } 
	  }     
    }
// Check is CheckBox checked
function getCheckedLength(fname, onlyOne) {
	var count = 0;
	if (fname.length > 1){
		for (i=0;i< fname.length;i++){
			if (fname[i].checked == true){
				count++;
			}
		}
	}
	else if (fname.checked == true){
		count = 1;
	}
	if(count < 1) {
		alert("请至少选择一笔订单!");
		return false;
	}
	// Only one check
	if(onlyOne && count > 1) {
		alert("请至多选择一笔订单!");				
		return false;
	}
	return true;
}  
	function isRadioBox(chkForm) {
		var radList = getRadioBox(chkForm);
		var radCount = radList.length;
		if(radCount == 0) {
			alert("请选择一种方式!");
			return false;
		}
		return true;
	}    
	function checkTel(val){
		var str = val.toString();
		for(var i=0; i < str.length;i++) {
			var ch = str.charAt(i);
			if((ch < '0' || ch > '9')&& ch !='-') return false;
		}
		return true;
	}
	function calculate(fcount,fprice,fresult){
		amt = 0.0;
		if(isEmpty(fcount.value)){
			alert("订货数量不能为空!");
			//document.all.fcount.focus();
			return false;
		}
		if(isNaN(fcount.value)){
			alert("订货数量必须为数字（包含小数）!");
			//document.all.fcount.focus();	
			fcount.value = "";		
			return false;			
		}else if(!isNaN(fcount.value)){
			if(fcount.value==0)
			{
				alert("订货数量必须大于0!");
				return false;
			}
			var val = parseFloat(fcount.value,10);
			var temp = fprice + "0";
			var price = parseFloat(fprice.innerText,1);
			amt =  val * price;
			amt = Math.round(amt * 10000)/10000;
			fresult.innerText = amt;
		}		
	}
	function changeprice(val,fprice,fcount,fresult){
		var temp = val;
		var str = temp.lastIndexOf("-")+ 1;
		var end = temp.length;					
		fprice.innerText = temp.substring(str,end);
		calculate(fcount,fprice,fresult);
	}        
	function IsPinYear(year)            //判断是否闰平年
  	{
    	if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;
  	}
  	function getMaxDay(year,month){
  		var day ;
  		if(month <=7){
  			if(month == 2){
				if(IsPinYear(year)){
					day = 29;
				}else{
					day = 28;
				}  				
  			}else{
  				if(month % 2 == 0){
  					day = 30;
  				}else{
  					day = 31;
  				}
  			}
  		}else if(month > 7 ){
  				if(month % 2 == 0){
  					day = 31;
  				}else{
  					day = 30;
  				}
  		}
  		return day;
  	}
	function StrLen(data) {
		var len = 0;
		for(i=0; i < data.length; i++) {
			code = data.charCodeAt ( i );
			if(code > 255) len += 2;
			else len ++;
		}
		return len
	}		
	

